package com.smz.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.smz.entity.TLogistics;
import com.smz.entity.TVehicleCar;
import com.smz.entity.TVehicleDriver;
import com.smz.service.TVehicleCarService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class TVehicleCarController {

    @Autowired
    private TVehicleCarService tVehicleCarService;

    @RequestMapping(value = "/tVehicleCar/all",method = RequestMethod.GET)
    public ResponseEntity<List<TVehicleCar>> findTVehicleCarAllGgy(){
        List<TVehicleCar> listTVehicleCar = tVehicleCarService.findTVehicleCarAllGgy();
        return ResponseEntity.ok(listTVehicleCar);
    }
    @ApiOperation("分页查询车辆信息")
    @GetMapping("/tVehicleCar/{current}/{size}")
    public ResponseEntity<IPage<TVehicleCar>> findTVehicleCarPage(@PathVariable("current") int current,
                                                                  @PathVariable("size") int size){
        IPage<TVehicleCar> page = tVehicleCarService.findTVehicleCarPage(current,size);
        return ResponseEntity.ok(page);
    }

    @ApiOperation("分页查询")
    @GetMapping("/tVehicleCar/{current}/{size}/{vehicleId}")
    public ResponseEntity<IPage<TVehicleCar>> findTVehicleCarPageId(@PathVariable("current") int current,
                                                                    @PathVariable("size") int size,
                                                                    @PathVariable("vehicleId") int vehicleId){
        IPage<TVehicleCar> page = tVehicleCarService.findTVehicleCarPageId(current,size,vehicleId);
        return ResponseEntity.ok(page);
    }

    @ApiOperation("分页查询")
    @GetMapping("/tVehicleCar/{current}/{size}/{vehicleName}/{numberPlate}")
    public ResponseEntity<IPage<TVehicleCar>> findTVehicleCarPageTwo(@PathVariable("current") int current,
                                                                     @PathVariable("size") int size,
                                                                     @PathVariable("vehicleName") String vehicleName,
                                                                     @PathVariable("numberPlate") String numberPlate){
        IPage<TVehicleCar> page = null;
        if ("null".equals(vehicleName)){
            page = tVehicleCarService.findTVehicleCarPageNameNumber(current,size,null,numberPlate);
        }else if ("null".equals(numberPlate)){
            page = tVehicleCarService.findTVehicleCarPageNameNumber(current,size,vehicleName,null);
        }else {
            page = tVehicleCarService.findTVehicleCarPageNameNumber(current,size,vehicleName,numberPlate);
        }
        return ResponseEntity.ok(page);
    }

    @ApiOperation("添加车辆信息")
    @PostMapping("/tVehicleCar")
    public ResponseEntity<String> addTVehicleCar(@RequestBody TVehicleCar tVehicleCar){
        tVehicleCarService.saveOrUpdate(tVehicleCar);
        return ResponseEntity.ok("ok");
    }

    @ApiOperation("修改车辆信息")
    @PutMapping("/tVehicleCar")
    public ResponseEntity<String> modifyTVehicleCar(@RequestBody TVehicleCar tVehicleCar){
        tVehicleCarService.saveOrUpdate(tVehicleCar);
        return ResponseEntity.ok("ok");
    }

    @ApiOperation("删除车辆信息")
    @DeleteMapping("/tVehicleCar/{id}")
    public ResponseEntity<String> removeTVehicleCar(@PathVariable("id") int id){
        tVehicleCarService.removeById(id);
        return ResponseEntity.ok("ok");
    }

    @ApiOperation("查询全部驾驶人")
    @GetMapping("/CarDriverName")
    public ResponseEntity<List<TVehicleDriver>> findCarDriverName(){
        List<TVehicleDriver> Driver = tVehicleCarService.findCarDriverName();
        return ResponseEntity.ok(Driver);
    }

    @ApiOperation("查询全部物流公司")
    @GetMapping("/CarLogisticsName")
    public ResponseEntity<List<TLogistics>> findLogisticsName(){
        List<TLogistics> Logistics = tVehicleCarService.findCarLogisticsName();
        return ResponseEntity.ok(Logistics);
    }
}
